package tcu.iot.gasmanage.api;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tcu.iot.gasmanage.common.Result;
import tcu.iot.gasmanage.common.utils.QuerySwitchUtils;
import tcu.iot.gasmanage.entity.datamanagement.EquipmentNumberQuery;
import tcu.iot.gasmanage.entity.datamanagement.UpdateRealTimeQuery;
import tcu.iot.gasmanage.service.DataManagementService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Api(value = "实时数据管理控制器")
@RestController
@RequestMapping("/dataManagement")
@CrossOrigin
public class DataManageController {

    @Resource
    private DataManagementService dataManagementService;

    @ApiOperation(value = "/getEquipmentNumberOptions", notes = "获得设备编好序列")
    @GetMapping("/getEquipmentNumberOptions")
    public Result getEquipmentNumberOptions() {
        return dataManagementService.getEquipmentNumber();
    }

    @ApiOperation(value = "/updateData", notes = "获得实时数据")
    @GetMapping("/updateData")
    public Result UpdateData(HttpServletRequest request) {
        EquipmentNumberQuery equipmentNumberQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), EquipmentNumberQuery.class);

        return dataManagementService.UpdateData(equipmentNumberQuery);
    }

    @ApiOperation(value = "/updateRealTimeData", notes = "获得实时数据")
    @GetMapping("/updateRealTimeData")
    public Result UpdateRealTimeData(HttpServletRequest request) {
        UpdateRealTimeQuery updateRealTimeQuery = JSON.parseObject(QuerySwitchUtils.QuerySwitch(request.getQueryString()), UpdateRealTimeQuery.class);

        return dataManagementService.UpdateRealTimeData(updateRealTimeQuery);
    }

}
